//
//  BrandTableViewCell.m
//  B_WatchHome
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 DHF. All rights reserved.
//

#import "BrandTableViewCell.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>

@implementation BrandTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.leftImageView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:self.leftImageView];
    
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.and.left.mas_equalTo(10);
        
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.equalTo(self.leftImageView.mas_right).offset(20);
        
    }];
    
    self.footLabel = [[UILabel alloc] init];
    self.footLabel.textColor = [UIColor brownColor];
    [self.contentView addSubview:self.footLabel];
    [self.footLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(30);
        
        make.left.equalTo(self.leftImageView.mas_right).offset(20);
        
    }];
    
    
    
    
}

- (void)setModel:(BrandModel *)model
{
    if (_model != model) {
        _model = model;
    }
    
    self.footLabel.text = self.model.ename;
    NSURL *url = [NSURL URLWithString:self.model.img];
    
    [self.leftImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
    //关键字高亮
    if (self.importantKey.length > 0) {
        NSMutableAttributedString *attrituteString = [[NSMutableAttributedString alloc] initWithString:model.name];
        NSRange range = [model.name rangeOfString:self.importantKey];
        [attrituteString setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor] , NSFontAttributeName : [UIFont boldSystemFontOfSize:18]} range:range];
        self.titleLabel.attributedText = attrituteString;
        return;
    }
    self.titleLabel.text = self.model.name;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
